﻿class VideoPlayer extends PlayerBase {
    public play(): void {
    }

    public stop(): void {
    }

    public pause(): void {
    }

    public resume(): void {
    }

    private video:egret.Video;
    public initData(obj: PaintLoader): void {

        super.initData(obj);
        this.video = new egret.Video();
        this.video.x = 0;                       //设置视频坐标x
        this.video.y = 0;                       //设置视频坐标y
        this.video.width = 1024;                 //设置视频宽
        this.video.height = 768;                //设置视频高
        this.video.fullscreen = false;          //设置是否全屏（暂不支持移动设备）
        this.video.poster= QNService.getFullUrl(this.paint.cover); //设置loding图
        this.video.load(QNService.getFullUrl(this.paint.data));
        this.addChild(this.video);              //将视频添加到舞台
        //监听视频加载完成
        this.video.once(egret.Event.COMPLETE,this.onLoaded,this);
        this.video.once(egret.Event.ENDED,this.onEnded,this);        
        //监听视频加载失败
        this.video.once(egret.IOErrorEvent.IO_ERROR,()=>console.log("onLoadErr~~"),this);        
        // var cantainer = <HTMLDivElement>document.getElementById("videoContainer");
        // cantainer.style.visibility = "visible";

        // cantainer.innerHTML = this.innerVideo;

        // var video = <HTMLVideoElement>document.getElementById("video");
        // video.style.visibility = "visible";
        // video.src = QNService.getFullUrl(this.paint.data);
        // video.poster = QNService.getFullUrl(this.paint.cover);
        // video.onended = () => {
        //     this.finish();
        // };

    }
    onEnded(){
        
        this.finish();
    }
    onLoaded(){
        
        this.video.play();
    }
    private innerVideo: string = "<video id='video' style='width: 1024px; height: 768px; ' autoplay='autoplay' controls='controls'></video>"

    public finish(): void {
        this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
    }


    public dispose(): void {
        this.video.close();
        // var video = <HTMLVideoElement>document.getElementById("video");
        // if (video) {
        //     video.pause();
        //     video.src = "";
        //     video.poster = "";
        //     video.style.visibility = "hidden";
        // }
        // var cantainer = <HTMLDivElement>document.getElementById("videoContainer");
        // cantainer.style.visibility = "hidden";
        // cantainer.innerHTML = "";
    }
}